<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            var tokens = ["eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJYNWVmbUNoIiwidXNlck5hbWUiOiLms5XlpJbni4LlvpIt5byg5LiJIiwiaWF0IjoxNjY3ODc4OTc2LCJleHAiOjE2NzA0NzA5NzZ9.sO-2zRVcr9WHsLktBRsSQhc7D7HUaG3fHMBN01pgQv8", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJTUkdyOTZnIiwidXNlck5hbWUiOiLlj7boia_ovrAiLCJpYXQiOjE2Njc4ODk5MTcsImV4cCI6MTY3MDQ4MTkxN30.dqxtavMfNfuuRQ-9HLMBu-zlz-DP1-8wXIPaSoSmuDA"];

            function getUrlParam(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                // console.log(reg);
                var r = decodeURI(window.location.search).substr(1).match(reg); //匹配目标参数
                // console.log(window.location.search.substr(1).match(reg));
                if (r != null) return unescape(r[2]);
                return null; //返回参数值
            }

            var ws = new WebSocket(`ws://localhost:3001?token=${tokens[getUrlParam("token")]}`);
            console.log(ws);
            ws.addEventListener("message", (e) => console.log(e));
        </script>
    </body>
</html>
